import Vue from 'vue'
import VueRouter from 'vue-router'

const Login = () =>
    import ( /* webpackChunkName: "group-login" */ '../views/login/Login.vue')
const Home = () =>
    import ( /* webpackChunkName: "group-home" */ '../views/home/Home.vue')
const Extension = () =>
    import ( /* webpackChunkName: "group-share" */ '../views/extension/Extension.vue')
const Apply = () =>
    import ( /* webpackChunkName: "group-apply" */ '../views/apply/Apply.vue')
const HomeStrategy = () =>
    import ( /* webpackChunkName: "group-home" */ '../views/home/strategy/HomeStrategy.vue')
const GameIntroduce = () =>
    import ( /* webpackChunkName: "group-share" */ '../views/extension/gameintroduce/GameIntroduce.vue')
const Withdrawal = () =>
    import ( /* webpackChunkName: "group-withdrawal" */ '../views/withdrawal/Withdrawal.vue')
const WithdrawalDetails = () =>
    import ( /* webpackChunkName: "group-withdrawal" */ '../views/withdrawal/childComps/WithdrawalDetails.vue')
const SpecificData = () =>
    import ( /* webpackChunkName: "group-withdrawal" */ '../views/withdrawal/childComps/SpecificData.vue')
const BindMain = () =>
    import ( /* webpackChunkName: "group-withdrawal" */ '../views/withdrawal/childComps/BindMain.vue')
const NoticeDateil = () =>
    import ( /* webpackChunkName: "group-detail" */ '../views/apply/childComps/NoticeDateil.vue')
const AboutUs = () =>
    import ( /* webpackChunkName: "group-setup" */ '../views/apply/setup/AboutUs.vue')
const Password = () =>
    import ( /* webpackChunkName: "group-setup" */ '../views/apply/setup/Password.vue')
const Feedback = () =>
    import ( /* webpackChunkName: "group-setup" */ '../views/apply/setup/Feedback.vue')
const ChangeLogin = () =>
    import ( /* webpackChunkName: "group-setup" */ '../views/apply/setup/ChangeLogin.vue')
const Changewithdrawal = () =>
    import ( /* webpackChunkName: "group-setup" */ '../views/apply/setup/Changewithdrawal.vue')
const Detail = () =>
    import ( /* webpackChunkName: "group-detail" */ '../views/detail/Detail.vue')
const DetailGamePromotion = () =>
    import ( /* webpackChunkName: "group-detail" */ '../views/detail/childComps/DetailGamePromotion.vue')

const GenerateCode = () =>
    import ( /* webpackChunkName: "group-code" */ '../views/extension/generatecode/GenerateCode.vue')
const PageTools = () =>
    import ( /* webpackChunkName: "group-page" */ '../views/page/PageTools.vue')
const RechargeManage = () =>
    import ( /* webpackChunkName: "group-page" */ '../views/page/RechargeManage.vue')
const RecordList = () =>
    import ( /* webpackChunkName: "group-page" */ '../views/page/childComps/RecordList.vue')
const StopServer = () =>
    import ( /* webpackChunkName: "group-page-gamedetail" */ '../views/page/StopServer.vue')
const VipQuery = () =>
    import ( /* webpackChunkName: "group-page-gamedetail" */ '../views/page/VipQuery.vue')
const GameActivitie = () =>
    import ( /* webpackChunkName: "group-page-gamedetail" */ '../views/page/GameActivitie.vue')
const WebGame = () =>
    import ( /* webpackChunkName: "group-page-type" */ '../views/page/WebGame.vue')
const BtGame = () =>
    import ( /* webpackChunkName: "group-page-type" */ '../views/page/BtGame.vue')
const DiscountGame = () =>
    import ( /* webpackChunkName: "group-page-type" */ '../views/page/DiscountGame.vue')
const AllGame = () =>
    import ( /* webpackChunkName: "group-home-type" */ '../views/page/AllGame.vue')
const StartServer = () =>
    import ( /* webpackChunkName: "group-page" */ '../views/page/StartServer.vue')
const Message = () =>
    import ( /* webpackChunkName: "group-home" */ '../views/page/Message.vue')
const DataManagement = () =>
    import ( /* webpackChunkName: "group-home" */ '../views/page/DataManagement.vue')
const RechargeItem = () =>
    import ( /* webpackChunkName: "group-page" */ '../views/page/childComps/RechargeItem.vue')


Vue.use(VueRouter)

// 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
        if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
        return originalPush.call(this, location).catch(err => err)
    }
    // 解决Vue-Router升级导致的Uncaught(in promise) navigation guard问题
const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace(location, onResolve, onReject) {
    if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
}

const routes = [{
    path: '/',
    redirect: '/login',
}, {
    path: '/login',
    component: Login,
    meta: {
        isturn: false
    },
}, {
    path: '/home',
    component: Home,
    meta: {
        isturn: true
    },
}, {
    path: '/extension',
    component: Extension,
    meta: {
        isturn: true
    },
}, {
    path: '/generate_code',
    component: GenerateCode,
    meta: {
        isturn: false
    },
}, {
    path: '/apply',
    component: Apply,
    meta: {
        isturn: false
    },
}, {
    path: '/gameinfo/gameid/:iid', //游戏详情页
    component: Detail,
    meta: {
        isturn: false
    },
}, , {
    path: '/detail_game_promotion', //游戏详情页
    component: DetailGamePromotion,
    meta: {
        isturn: false
    },
}, {
    path: '/strategy',
    component: HomeStrategy,
    meta: {
        isturn: false
    },
}, {
    path: '/game_introduce',
    component: GameIntroduce,
    meta: {
        isturn: true
    },
}, {
    path: '/withdrawal',
    component: Withdrawal,
    meta: {
        isturn: false
    },
}, {
    path: '/binding_card',
    component: BindMain,
    meta: {
        isturn: false
    },
}, {
    path: '/notice_detail',
    component: NoticeDateil,
    meta: {
        isturn: false
    },
}, {
    path: '/about_us',
    component: AboutUs,
    meta: {
        isturn: false
    },
}, {
    path: '/password',
    component: Password,
    meta: {
        isturn: false
    },
}, {
    path: '/feedback',
    component: Feedback,
    meta: {
        isturn: false
    },
}, {
    path: '/change_login_password',
    component: ChangeLogin,
    meta: {
        isturn: false
    },
}, {
    path: '/change_withdrawal_password',
    component: Changewithdrawal,
    meta: {
        isturn: false
    },
}, {
    path: '/withdrawal_details',
    component: WithdrawalDetails,
    meta: {
        isturn: false
    },
}, {
    path: '/specific_data',
    component: SpecificData,
    meta: {
        isturn: false
    },
}, {
    path: '/page_tools',
    component: PageTools,
    meta: {
        isturn: false
    },
}, {
    path: '/recharge_manage',
    component: RechargeManage,
    meta: {
        isturn: false
    },
}, {
    path: '/record_list',
    component: RecordList,
    meta: {
        isturn: false
    },
}, {
    path: '/stop_server',
    component: StopServer,
    meta: {
        isturn: false
    },
}, {
    path: '/vip_query',
    component: VipQuery,
    meta: {
        isturn: false
    },
}, {
    path: '/game_activitie',
    component: GameActivitie,
    meta: {
        isturn: false
    },
}, {
    path: '/web_game',
    component: WebGame,
    meta: {
        isturn: false
    },
}, {
    path: '/bt_game',
    component: BtGame,
    meta: {
        isturn: false
    },
}, {
    path: '/discount_game',
    component: DiscountGame,
    meta: {
        isturn: false
    },
}, {
    path: '/all_game',
    component: AllGame,
    meta: {
        isturn: false
    },
}, {
    path: '/start_server',
    component: StartServer,
    meta: {
        isturn: false
    },
}, {
    path: '/message',
    component: Message,
    meta: {
        isturn: false
    },
}, {
    path: '/data_management',
    component: DataManagement,
    meta: {
        isturn: false
    },
}, {
    path: '/recharge_item',
    component: RechargeItem,
    meta: {
        isturn: false
    },
}]

const router = new VueRouter({
    routes
})


// 导航守卫、路由守卫、路由拦截
// router.beforeEach((to,from,next) => {
// 验证token，只有存在token的时候，才能跳转到内容页。
//   let token = $cookies.get('token')
//   if(token || to.path === "/login"){
//       next();
//   }else{
//       next("/login")
//   }
// })

export default router